package com.cloudbroker.bcs.csvc.lightinvesting.api.util;

import com.cloudbroker.bcs.csvc.lightinvesting.api.constants.LedErrorCodes;
import com.cloudbroker.bcs.csvc.lightinvesting.api.constants.LedFields;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by fangyf18371 on 2016/7/15.
 */
public class LedUtil {
    public static boolean isSuccess(Map<String, Object> result) {
        if (null != result) {
            Object error_no = result.get(LedFields.ERROR_NO);
            return null == error_no || LedErrorCodes.SUCCESS.equals(String.valueOf(error_no));
        }
        return false;
    }

    public static Map<String, Object> genCommErrorResult() {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put(LedFields.ERROR_NO, "-1");
        result.put(LedFields.ERROR_INFO, "Execute Error.");
        return result;
    }

    public static Map<String, Object> genErrorResult(int errorNo, String errorInfo) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put(LedFields.ERROR_NO, errorNo);
        result.put(LedFields.ERROR_INFO, errorInfo);
        return result;
    }

    public static Map<String, Object> genSuccessResult() {
        Map<String, Object> result = new HashMap<String, Object>();
        return setSuccessResult(result);
    }

    public static Map<String, Object> setSuccessResult(Map<String, Object> map) {
        map.put(LedFields.ERROR_NO, LedErrorCodes.SUCCESS);
        map.put(LedFields.ERROR_INFO, "Execute success.");
        return map;
    }

    public static Map<String, Object> setSuccessResult(Map<String, Object> map, String errorInfo) {
        map.put(LedFields.ERROR_NO, LedErrorCodes.SUCCESS);
        map.put(LedFields.ERROR_INFO, errorInfo);
        return map;
    }

    public static Map<String, Object> setErrorResult(Map<String, Object> map, int errorNo, String errorInfo) {
        map.put(LedFields.ERROR_NO, errorNo);
        map.put(LedFields.ERROR_INFO, errorInfo);
        return map;
    }
}
